//
//  AppDelegate.swift
//  HFWeChat
//
//  Created by 黄来峰 on 16/4/17.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
       
//      print(HFUserAccountTools.sharedTools.getUserAccount())
//        print(HFUserAccountTools.sharedTools.userAccount)
        
        
        
        //初始化控件
        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        //设置window的背景颜色
//        window?.backgroundColor = UIColor.whiteColor()
        
        window?.backgroundColor = UIColor.redColor()
        //设置window的根视图
//        window?.rootViewController = HFMainTabbarController()
//        setDefaultVc()
        setDefaultVc()
        
              //设置window为主视图
        window?.makeKeyAndVisible()
        
        
        //注册通知的观察者用来接收通知切换根视图
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "switchDefaultVc:", name: SWITCHDEFAULTVC, object: nil)

//        setUpAppTintColor()
        return true
    }
    
  //MARK: -判断用户是否登录来决定使用哪个根视图
    func setDefaultVc(){
        let userAccount = HFUserAccountTools.sharedTools
        if userAccount.isLogin{
        
        window?.rootViewController = HFWelcomViewController()
        }else{
        window?.rootViewController = HFMainTabbarController()
        }
    }

     //MARK: -切换根视图
    func switchDefaultVc(notify: NSNotification){
        
//         window?.rootViewController = HFWelcomViewController()
        //切换到首页
        if notify.object != nil{
            window?.rootViewController = HFMainTabbarController()
        }else{
        //切换到欢迎界面
            window?.rootViewController = HFWelcomViewController()
        }
    }
    
     //MARK: -移除通知
    deinit{
    
    NSNotificationCenter.defaultCenter().removeObserver(self)
    
    }
    
    
    
//    //设置app全局的颜色
//    func setUpAppTintColor(){
//    这句话设置的属性是全局的属性
//        UITabBar.appearance().tintColor = UIColor.orangeColor()
//    
//    
//    }
 
}
